<?php

namespace app\admin\controller\hospital;

use app\common\controller\Backend;
use think\Db;
use think\Request;

/**
 * 
 *
 * @icon fa fa-circle-o
 */
class Index extends Backend
{

    /**
     * Index模型对象
     * @var \app\admin\model\hospital\Index
     */
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\hospital\Index;
        $this->view->assign("statusList", $this->model->getStatusList());
    }



    /**
     * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
     * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
     * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
     */

    /**
     *  服务管理
     */

    public function service(){

        if ($this->request->isPost()){

            $services=$this->request->param('services/a');

            foreach ($services as $k=>$v){


                if (isset($v['status'])){
                    $u['status']=$v['status'];
                }else{
                    $u['status']=0;
                }

                $u['money']=$v['price'];

                Db::name('hospital_service')
                    ->where('id','eq',$v['id'])
                    ->update($u);
            }

            $this->success('保存成功');
        }


        $ids=$this->request->param('ids');

        $lists=Db::name('service')->select();

        foreach ($lists as $k=>$v){

            $find=Db::name('hospital_service')->where('hid','eq',$ids)
                ->where('sid','eq',$v['id'])
                ->find();

            if (!$find){
                $arr=$v;
                $arr['hid']=$ids;
                $arr['sid']=$v['id'];
                unset($arr['id']);

                Db::name('hospital_service')->data($arr)->insert();
            }

        }

        $list=Db::name('hospital_service')->where('hid','eq',$ids)->select();



        $this->view->assign('lists',$list);

        return $this->view->fetch();

    }


}



















